<template>
    <div>
        <h1>Phone</h1>
        <p>msg：{{ msg }}</p>
        <input
            type="text"
            v-model="pad"
            @keyup.enter="changePad"
            placeholder="修改平板MSG，输入完按回车"
        />
    </div>
</template>

<script>
import pubsub from "pubsub-js";

export default {
    name: "Phone",
    data() {
        return {
            msg: "我是Phone",
            pad: "",
        };
    },
    mounted() {
        const pubId = pubsub.subscribe("modPhone", (msgName, data) => {
            this.msg = data;
        });
    },
    methods: {
        changePad() {
            pubsub.publish("modPad", this.pad);
        },
    },
    // 及时解绑自定义事件
    beforeDestroy() {
        pubsub.unsubscribe(this.pubId);
    },
};
</script>

<style></style>
